package com.five.controller;

import com.five.exception.BusinessException;
import com.five.result.Result;
import com.five.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;


    /**
     * 登录
     * @param params
     * @return
     */
    @PostMapping
    public Result login(@RequestBody Map<String,Object> params){
        try {
            Map<String, Object> map = loginService.login(params);
            return Result.success(map);
        } catch (BusinessException e) {
            return Result.error(e.getMessage());
        }catch (Exception e) {
            e.printStackTrace();
            return Result.error("系统异常");
        }
    }
}
